From: Florian Müllner Date: Tue, 24 Mar 2020 06:44:31 +0000 (+0100) Subject: screenshot: Return error when stream creation fails X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~751^2^2~72 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=eb51942a051f18f5993914968fcefb00a56c3625;p=gnome-shell.git screenshot: Return error when stream creation fails The Shell.Screenshot API expects valid output streams for writing the completed screenshot, not NULL. Handle this properly by returning an error instead of passing it on to the screenshot. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1123 --- diff --git a/js/ui/screenshot.js b/js/ui/screenshot.js index 09f5c5109..78afc4ae4 100644 --- a/js/ui/screenshot.js +++ b/js/ui/screenshot.js @@ -84,7 +84,7 @@ var ScreenshotService = class { } } - _createStream(filename) { + _createStream(filename, invocation) { if (filename == '') return [Gio.MemoryOutputStream.new_resizable(), null]; @@ -94,6 +94,7 @@ var ScreenshotService = class { let stream = file.replace(null, false, Gio.FileCreateFlags.NONE, null); return [stream, file]; } catch (e) { + invocation.return_value(GLib.Variant.new('(bs)', [false, ''])); return [null, null]; } } @@ -104,10 +105,11 @@ var ScreenshotService = class { return [stream, file]; } catch (e) { if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.EXISTS)) - return [null, null]; + break; } } + invocation.return_value(GLib.Variant.new('(bs)', [false, ''])); return [null, null]; } @@ -169,7 +171,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot_area(x, y, width, height, stream, (o, res) => { @@ -190,7 +194,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot_window(includeFrame, includeCursor, stream, (o, res) => { @@ -211,7 +217,9 @@ var ScreenshotService = class { if (!screenshot) return; - let [stream, file] = this._createStream(filename); + let [stream, file] = this._createStream(filename, invocation); + if (!stream) + return; screenshot.screenshot(includeCursor, stream, (o, res) => {